import axiosInstance from '@/api/axiosInstance'

// 定义查询参数对象
interface ListParams {
  userName?: string
  status?: string
  email?: string
  roles?: string
  page?: number
  pageSize?: number
}

/**
 * 获取用户列表
 * @param params 查询参数
 */
export const getUserList = async (params?: ListParams) => {
  return axiosInstance.get('/admin/admin-user', { params })
}

/**
 * 获取用户详情
 * @param id 用户 ID
 */
export const getUserDetail = async (id: number) => {
  return axiosInstance.get(`/admin/admin-user/${id}`)
}

/**
 * 创建用户
 * @param data 用户数据
 */
export const createUser = async (data: any) => {
  return axiosInstance.post('/admin/admin-user', data)
}

/**
 * 更新用户
 * @param id 用户 ID
 * @param data 用户数据
 * @returns
 */
export const updateUser = async (id: number, data: any) => {
  return axiosInstance.put(`/admin/admin-user/${id}`, data)
}

/**
 * 删除用户
 * @param id 用户 ID
 */
export const deleteUser = async (id: number) => {
  return axiosInstance.delete(`/admin/admin-user/${id}`)
}

export const exportUserList = async (params?: ListParams) => {
  return axiosInstance.get('/admin/admin-user/export', { params, responseType: 'blob', timeout: 60000 })
}
